package com.shop.shoppingmall.controller;

import com.shop.shoppingmall.entity.ShFollowShop;
import com.shop.shoppingmall.service.ShFollowShopService;
import com.shop.shoppingmall.util.api.vo.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 店铺关注(ShFollowShop)表控制层
 *
 * @author makejava
 * @since 2020-09-09 10:06:18
 */
@RestController
@RequestMapping("shFollowShop")
@CrossOrigin
public class ShFollowShopController {
    /**
     * 服务对象
     */
    @Resource
    private ShFollowShopService shFollowShopService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public ShFollowShop selectOne(String id) {
        return this.shFollowShopService.queryById(id);
    }

    /**
     * 关注或取消关注商铺
     * @param map
     * @return
     */
    @PostMapping("/followShop")
    public Result followShop(@RequestBody Map map, HttpServletRequest request){
        String merchantId = (String) map.get("merchantId");
        String isKeep = (String) map.get("isKeep");
        if(isKeep.equals("1")){
            return shFollowShopService.addFollowShop(request,merchantId);
        }else {
            return shFollowShopService.deleteFollowShop(request,merchantId);
        }
    }

    /**
     * 查询该用户关注的所有商铺信息
     * @param request
     * @return
     */
    @GetMapping("/selectAllFollowShop")
    public Result selectAllFollowShop(HttpServletRequest request){
        return shFollowShopService.selectAllFollowShop(request);
    }

}